package com.rightsidetech.scheduler.task;

import com.rightsidetech.activity.service.ActGiftActivityStatisService;
import com.rightsidetech.activity.service.ActGiftService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
@EnableScheduling
public class ActGiftTask {
    @Resource
    private ActGiftService actGiftService;
    @Resource
    private ActGiftActivityStatisService actGiftActivityStatisService;

    /**
     * 0点10分 执行换购活动到期  修改状态为结束
     */
    @Scheduled(cron = "0 10 0 * * ?")
    public void giftActivityTask() {
        try {
            //进行中的 到结束时间的修改状态
            actGiftService.updateStatus();
        } catch (Exception e) {
            log.error("换购活动到期结束任务异常", e);
        }
    }

    /**
     * 1点0分 执行换购活动统计
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void giftStatisticsTask(){
        try {
            actGiftActivityStatisService.updateGiftStatistics();
        }catch (Exception e){
            log.error("换购活动统计任务异常",e);
        }
    }

}
